package sk.tonyb.crawler.configuration;

import sk.tonyb.crawler.codebook.ConfigurationFile;
import sk.tonyb.library.configuration.PropertyConfigurator;

/** 
 * Class, which store configuration values. 
 * 
 * @author Anton Balucha
 * @since 16.10.2011
 * @last_modified 16.10.2011
 */
public class ConfigReader {
	
	/** Singleton. */
	private static ConfigReader configReader = null;
	
	// values
	private String pageStart = null;
	private String pageCountMax = null;
	private String downloadedLocation = null;
	
	/** Constructor. */
	private ConfigReader() {
		this.init();
	}
	
	/** Method, which return instance of {@link ConfigReader}. */
	public static synchronized ConfigReader getInstance() {
		
		if(ConfigReader.configReader == null) {
			ConfigReader.configReader = new ConfigReader();
		}
		
		return ConfigReader.configReader;
	}
	
	/** Method, which initialize values. */
	private synchronized void init() {
		this.readPageStart();
		this.readPageCountMax();
		this.readDownloadedLocation();
	}
	
	/** Method reads value of key page.start. */
	private synchronized void readPageStart() {
		this.pageStart = PropertyConfigurator.getInstance().getFirstValue(ConfigurationFile.PAGE_START_KEY);
	}
	
	/** Method reads value of key page.count.max. */
	private synchronized void readPageCountMax() {
		this.pageCountMax = PropertyConfigurator.getInstance().getFirstValue(ConfigurationFile.PAGE_COUNT_MAX_KEY);
	}
	
	/** Method reads value of key downloaded.location. */
	private synchronized void readDownloadedLocation() {
		this.downloadedLocation = PropertyConfigurator.getInstance().getFirstValue(ConfigurationFile.DOWNLOADED_LOCATION_KEY);
	}
	
	/** Method return unprocessed value of key page.start. */
	public synchronized String getPageStart() {
		return this.pageStart;
	}
	
	/** Method return unprocessed value of key page.count.max. */
	public synchronized String getPageCountMax() {
		return this.pageCountMax;
	}
	
	/** Method return unprocesssed value of key downloaded.location. */
	public synchronized String getDownloadedLocation() {
		return this.downloadedLocation;
	}
	
	/** Method, which return actual values as string. */
	public synchronized String toString() {
		return "[this.pageStart = " + this.pageStart + "] [this.pageCountMax = " + this.pageCountMax + "] [this.downloadedLocation = " + this.downloadedLocation + "]";
	}
}
